package main.java.indi.zyj.sword;

public class CuttingBamboo {

    public int cuttingBamboo(int bamboo_len) {

        if (bamboo_len <= 3) {
            return bamboo_len - 1;
        }

        int a = bamboo_len / 3, b = bamboo_len % 3;
        long res = 1, p = 1000000007;

        for (int i = 0; i < a; i++) {
            res = res * 3 % p;
            res--;
        }

        if (b == 0) {
            return (int) res;
        }
        if (b == 1) {
            return (int) res * 4;
        }

        return (int) res * 2;

    }


}
